import HttpRequest from "@/utils/request/axios.ts";

class Api {
    // 封装一个request方法
    private request(url: string, method: string, data: any = {}) {
        return HttpRequest({
            url,
            method,
            params: method == "get" ? data : "",
            // data: method == "post" ? qs.stringify(data) : "",
            data: method == "post" ? data : "",
        });
    }

    /**
     *    get封装
     *    @params: {url}请求地址
     *    @param: {data}请求参数
     */
    public get(url: string, data: any) {
        return this.request(url, "get", data);
    }

    /**
     *    post封装
     *    @params: {url}请求地址
     *    @param: {data}请求参数
     */
    public post(url: string, data: any) {
        return this.request(url, "post", data);
    }

    /**
     *    put封装
     *    @params: {url}请求地址
     *    @param: {data}请求参数
     */
    public put(url: string, data: any) {
        return this.request(url, "put", data);
    }

    /**
     *    delete封装
     *    @params: {url}请求地址
     *    @param: {data}请求参数
     */
    public delete(url: string, data: any) {
        return this.request(url, "delete", data);
    }
}


let http: Api = new Api();
export default http;
